// utils/useAutoHide.js
import { ref, onBeforeUnmount } from 'vue'

export default function(initialState = false, duration = 5000) {
  const state = ref(initialState)
  let timeoutId = null

  const setAutoHide = (value) => {
    state.value = value
    if (value) {
      clearTimeout(timeoutId)
      timeoutId = setTimeout(() => {
        state.value = false
      }, duration)
    }
  }

  onBeforeUnmount(() => {
    clearTimeout(timeoutId)
  })

  return [state, setAutoHide]
}
